package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.BoardProportionInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface BoardProportionInfoDao {
    @Results(id = "boardProportionInfoResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "code0301", property = "code0301", jdbcType = JdbcType.VARCHAR),
            @Result(column = "version0301", property = "version0301", jdbcType = JdbcType.VARCHAR),
            @Result(column = "company_name", property = "companyName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "company_code", property = "", jdbcType = JdbcType.VARCHAR),
            @Result(column = "layer", property = "layer", jdbcType = JdbcType.INTEGER),
            @Result(column = "nh3c_BoTime", property = "nh3cBoTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "application_time", property = "applicationTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "product_board_name", property = "productBoardName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "qty", property = "qty", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "is_manual", property = "isManual", jdbcType = JdbcType.INTEGER)
    })

    /*
     *查询单个
     */
    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.BOARD_PROPORTION_INFO +
            " where id = #{id}" +
            "</script>")
    BoardProportionInfo getById(@Param("id") Integer id);

    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.BOARD_PROPORTION_INFO +
            "</script>")
    @ResultMap(value = "boardProportionInfoResultMap")
    List<BoardProportionInfo> getAll();

    @Insert("insert into tb_board_proportion_info(code0301, version0301, company_name, company_code, layer, application_time, product_board_name, qty, create_time, update_time, update_user, is_manual,nh3c_BoTime)" +
            "values (#{code0301}, #{version0301}, #{companyName}, #{companyCode}, #{layer}, #{applicationTime}, #{productBoardName}, #{qty}, #{createTime}, #{updateTime}, #{updateUser}, #{isManual},#{nh3cBoTime})")
    Integer insert(BoardProportionInfo boardProportionInfo);

    @Update("<script> " +
            "update " + DB2TableName.BOARD_PROPORTION_INFO +
            "<set> " +
            "<if test='code0301 != null and code0301 != \"\"'>" +
            " code0301 = #{code0301}," +
            "</if>" +
            "<if test='version0301 != null and version0301 != \"\"'>" +
            " version0301 = #{version0301}," +
            "</if>" +
            "<if test='companyName != null and companyName != \"\"'>" +
            " company_name = #{companyName}," +
            "</if>" +
            "<if test='companyCode != null and companyCode != \"\"'>" +
            " company_code = #{companyCode}," +
            "</if>" +
            "<if test='layer != null '>" +
            " layer = #{layer}," +
            "</if>" +
            "<if test='applicationTime != null '>" +
            " application_time = #{applicationTime}," +
            "</if>" +
            "<if test='qty != null '>" +
            " qty = #{qty}," +
            "</if>" +
            "<if test='createTime != null'>" +
            " create_time = #{createTime}," +
            "</if>" +
            "<if test='updateTime != null'>" +
            " update_time = #{updateTime}," +
            "</if>" +
            "<if test='updateUser != null'>" +
            " update_user = #{updateUser}," +
            "</if>" +
            "<if test='isManual != null'>" +
            " is_manual = #{isManual}," +
            "</if>" +
            "</set> " +
            "where id = #{id}" +
            "</script>")
    Integer update(BoardProportionInfo boardProportionInfo);

    @Delete("delete from " + DB2TableName.BOARD_PROPORTION_INFO + " where id = #{id}")
    Integer deleteById(Integer id);

    @Delete("delete from " + DB2TableName.BOARD_PROPORTION_INFO + " where is_manual = 2")
    Integer deleteByType();
}
